package com.gets.web.test;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * Created by me675 on 2016/9/25.
 */
public class FixBug {
    public static void main(String args[]) {
        InsertImageSet();
    }

    public static void InsertIdImageSetList() {
        MysqlHelper mysqlHelper = new MysqlHelper();
        try {
            List<Map<String, Object>> list = mysqlHelper.returnMultipleResult("select id,cover_url from image_set_list", null);
            for (Map<String, Object> map : list) {
                String url = map.get("cover_url").toString();
                String newUrl[] = url.split("/");
                if (newUrl.length == 2)
                    mysqlHelper.addDeleteModify("update image_set_list set cover_url = '" + newUrl[0] + "/" + map.get("id").toString() + "/" + newUrl[1] + "' where cover_url = '" + url + "'", null);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            mysqlHelper.closeconnection();
        }
    }

    public static void ImageSet() {
        MysqlHelper mysqlHelper = new MysqlHelper();
        try {
            List<Map<String, Object>> list = mysqlHelper.returnMultipleResult("select url from image_set", null);
            for (Map<String, Object> map : list) {
                if (map.get("url").toString().contains("/"))
                    System.out.println(map.get("url").toString());
              /*  String url = map.get("url").toString();
                if (!url.contains("/")) {
                    String newUrl = url.substring(0, 8) + "/" + url.substring(8, url.length());
                    mysqlHelper.addDeleteModify("update image_set_list set cover_url = '" + newUrl + "' where cover_url = '" + url + "'", null);
                }*/
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            mysqlHelper.closeconnection();
        }
    }

    public static void InsertImageSet() {
        MysqlHelper mysqlHelper = new MysqlHelper();
        try {
            List<Map<String, Object>> list = mysqlHelper.returnMultipleResult("select all_images_id,url from image_set", null);
            for (Map<String, Object> map : list) {
                String newUrl[] = map.get("url").toString().split("/");
                if (newUrl.length == 3) {
                    mysqlHelper.addDeleteModify("update image_set set url = '" + newUrl[0] + "/" + map.get("all_images_id").toString() + "/" + newUrl[2] + "' where url = '" + map.get("url").toString() + "'", null);
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            mysqlHelper.closeconnection();
        }
    }

    public void ImageSetList() {
        MysqlHelper mysqlHelper = new MysqlHelper();
        try {
            List<Map<String, Object>> list = mysqlHelper.returnMultipleResult("select cover_url from image_set_list", null);
            for (Map<String, Object> map : list) {
                String url = map.get("cover_url").toString();
                if (!url.contains("/")) {
                    String newUrl = url.substring(0, 8) + "/" + url.substring(8, url.length());
                    mysqlHelper.addDeleteModify("update image_set_list set cover_url = '" + newUrl + "' where cover_url = '" + url + "'", null);
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            mysqlHelper.closeconnection();
        }
    }
}
